<?php

namespace App\Models;


class ClusterMember extends Orm
{
    //
    protected $table = 'cluster_member';
    protected $dateFormat = 'U';
    public $timestamps = true;

    public function clusterInfo()
    {
        return $this->belongsTo(Cluster::class, 'cluster_id');
    }

    public function dragonInfo()
    {
        return $this->belongsTo(Drag::class, 'cluster_id', 'cluster_id');
    }

    public function selfCluster()
    {
        return $this->hasMany(self::class, 'cluster_id', 'cluster_id')->where('status', 1);
    }

    public function userInfo()
    {
        return $this->belongsTo(Users::class, 'user_id');
    }

    public static function checkOpStatus($clusterId, $userId)
    {
        $member = self::where('cluster_id', $clusterId)->whereRaw("(role = 1 or role =2)")->where('user_id', $userId)->where('status',1)->first();
        return !empty($member) ? 1 : 0;
    }

    public static function showVerify($clusterId, $userId)
    {
        $member = self::where('cluster_id', $clusterId)->where('user_id', $userId)->where('status',1)->first();
        return !empty($member) ? 1 : 0;
    }
}
